<template>
  <div>
    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="page"
      :page-sizes="[10, 20, 30, 40]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      class="pagination"
      :url="url"
    >
    </el-pagination>
  </div>
</template>

<script>
import { getData } from '@/utils/table'

export default {
  props: {
    total: Number,
    url: String
  },
  data () {
    return {
      page: 1,  //当前页数
      size: 10 //每页显示数
    }
  },
  created () {
    getData(this.$parent, '/works', { page: this.page, size: this.size }, ['completed'])
  },
  methods: {
    // 分页操作方法
    handleSizeChange (val) {
      this.$parent.loading = true
      this.size = val
      this.page = 1
      getData(this.$parent, '/works', { page: this.page, size: this.size }, ['completed'])
    },
    handleCurrentChange (val) {
      this.$parent.loading = true
      this.page = val
      getData(this.$parent, '/works', { page: this.page, size: this.size }, ['completed'])
    },
  }
}
</script>

<style lang="less"></style>